import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import style
style.use('ggplot')
%matplotlib inline
import plotly
import plotly.express as px
import plotly.graph_objects as go
import cufflinks as cf
import plotly.offline as pyo
from plotly.offline import init_notebook_mode,plot,iplot
import folium
plt.rcParams['figure.figsize']=12,8
pyo.init_notebook_mode(connected=False)
cf.go_offline()
df=pd.read_excel("Covid cases in India.xlsx",header=0)
df
df.drop("S. No.",axis=1,inplace=True)
df
df['Total cases']=df['Total Confirmed cases (Indian National)']+df['Total Confirmed cases ( Foreign National )']
df
total_cases_overall=df['Total cases'].sum()
print('the total no of confimes cases till now in INDIA is',total_cases_overall)
df['Total Active cases']= df['Total cases']-(df['Cured']+df['Death'])
df
df.style.background_gradient(cmap='Blues')
# if we want to see only active cases
# .sum method is used to represent the data
# to make the data good... use. to_frame
Total_active_cases=df.groupby('Name of State / UT')['Total Active cases'].sum().sort_values(ascending=False).to_frame()
Total_active_cases
# this works over on dataframe.. so make the dataframe of data first
Total_active_cases.style.background_gradient(cmap='Reds')
#using pandas
df.plot(kind='bar',x='Name of State / UT',y='Total cases')
# using matplotlib
plt.bar(df['Name of State / UT'],df['Total cases'])
plt.xticks(rotation=60)
plt.show()
#using plotly
df.iplot(kind='bar',x='Name of State / UT',y='Total cases')
#plotly express
px.bar(df,x='Name of State / UT',y='Total cases')
#scatter using matplotlib
plt.scatter(df['Name of State / UT'],df['Total cases'])
plt.xticks(rotation=60)
plt.show()
#scatter plot using plotly
df.iplot(kind='scatter',x='Name of State / UT',y='Total cases',mode='markers+lines',title='my Graph',
xTitle='Name of State / UT',yTitle='Total cases',colors='green',size=20)
# scatter plot using plotly express
px.scatter(df,x='Name of State / UT',y='Total cases')
# matplotlib
fig=plt.figure(figsize=(12,8),dpi=200) ## dpi=dots per inches, it can zoom the graph
axes=fig.add_axes([0,0,1,1])
axes.bar(df['Name of State / UT'],df['Total cases'])
plt.show()
#plotly
fig=go.Figure()
fig.add_trace(go.Bar(x=df['Name of State / UT'],y=df['Total cases'])) # add_trace= add layout
fig.update_layout(title='My Graph',xaxis=dict(title='Name of State / UT'),yaxis=dict(title='Total cases'))
#Map
indian_coordinate=pd.read_excel("Indian Coordinates.xlsx")
indian_coordinate
df_full=pd.merge(indian_coordinate,df,on='Name of State / UT')
df_full
# tiles= types of map graohs
map=folium.Map(location=[20,70],zoom_start=4,tiles='Stamenterrain')
for lat,long,value,name in zip(df_full['Latitude'],df_full['Longitude'],df_full['Total cases'],df_full['Name of State / UT']):
folium.CircleMarker([lat,long],radius=value*0.8,popup=('<strong>State</strong>: '+str(name).capitalize()+'<br>''<strong>Total Cases</strong>: ' + str(value)+ '<br>'),color='red',fill_color='red',fill_opacity=0.3).add_to(map)
map
dbd_india=pd.read_excel("per_day_cases.xlsx",parse_dates=True,sheet_name='India')
dbd_india
dbd_italy=pd.read_excel("per_day_cases.xlsx",parse_dates=True,sheet_name='Italy')
dbd_korea=pd.read_excel("per_day_cases.xlsx",parse_dates=True,sheet_name='Korea')
dbd_wuhan=pd.read_excel("per_day_cases.xlsx",parse_dates=True,sheet_name='Wuhan')
#visualization of data of fpur countries
# using matplotlib
fig=plt.figure(figsize=(10,5),dpi=200)
axes=fig.add_axes([0.1,0.1,0.8,0.8])
axes.bar(dbd_india['Date'],dbd_india['Total Cases'],color='Blue')
axes.set_xlabel('Date')
axes.set_ylabel('Total cases')
axes.set_title('confirmed cases in INDIA')
plt.show()
# using plotly express as we can use plotly as well to show more graphs
fig=px.bar(dbd_india,x='Date',y='Total Cases',color='Total Cases',title='confirmed cases in INDIA')
fig.show()
fig=px.bar(dbd_italy,x='Date',y='Total Cases',color='Total Cases',title='confirmed cases in Italy')
fig.show()
fig=px.bar(dbd_korea,x='Date',y='Total Cases',color='Total Cases',title='confirmed cases in korea')
fig.show()
fig=px.bar(dbd_wuhan,x='Date',y='Total Cases',color='Total Cases',title='confirmed cases in wuhan')
fig.show()
#Plotly
dbd_india.iplot(kind='scatter',x='Date',y='Total Cases',mode='lines+markers')
#plotly graph_objects
fig=go.Figure()
fig.add_trace(go.Scatter(x=dbd_india['Date'],y=dbd_india['Total Cases'],mode='lines+markers'))
# subplot using Bar graph
from plotly.subplots import make_subplots
fig=make_subplots(
rows=2,cols=2,
specs=[[{"secondary_y":True},{"secondary_y":True}],[{"secondary_y":True},{"secondary_y":True}]],
subplot_titles=("S.Korea","Italy","India","Wuhan"))
fig.add_trace(go.Bar(x=dbd_korea['Date'],y=dbd_korea['Total Cases'],
marker=dict(color=dbd_korea['Total Cases'],coloraxis="coloraxis")),1,1)
fig.add_trace(go.Bar(x=dbd_italy['Date'],y=dbd_italy['Total Cases'],
marker=dict(color=dbd_italy['Total Cases'],coloraxis="coloraxis")),1,2)
fig.add_trace(go.Bar(x=dbd_india['Date'],y=dbd_india['Total Cases'],
marker=dict(color=dbd_india['Total Cases'],coloraxis="coloraxis")),2,1)
fig.add_trace(go.Bar(x=dbd_wuhan['Date'],y=dbd_wuhan['Total Cases'],
marker=dict(color=dbd_wuhan['Total Cases'],coloraxis="coloraxis")),2,2)
fig.update_layout(coloraxis=dict(colorscale='Bluered_r'),showlegend=False,title_text="Total Cases in 4 Countries")
fig.update_layout(plot_bgcolor='rgb(230,230,230)')
# worldmap for corona Virus
df1=pd.read_csv("covid_19_data.csv",parse_dates=['Last Update'])
df1.head()
df1.rename(columns={'ObservationDate':'Date','Country/Region':'Country'},inplace=True)
df1.head()
df1.query('Country=="India"')
df1.groupby('Date').sum()
confirmed=df1.groupby('Date').sum()['Confirmed'].reset_index()
death=df1.groupby('Date').sum()['Deaths'].reset_index()
recovered=df1.groupby('Date').sum()['Recovered'].reset_index()
fig=go.Figure()
fig.add_trace(go.Scatter(x=confirmed['Date'],y=confirmed['Confirmed'],mode='lines+markers',name='Confirmed',line=dict(color='blue',width=2)))
fig.add_trace(go.Scatter(x=death['Date'],y=death['Deaths'],mode='lines+markers',name='Deaths',line=dict(color='red',width=2)))
fig.add_trace(go.Scatter(x=recovered['Date'],y=recovered['Recovered'],mode='lines+markers',name='Recovered',line=dict(color='green',width=2)))
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
df_confirmed=pd.read_csv("time_series_covid_19_confirmed.csv")
df_confirmed.rename(columns={'Country/Region':'Country'},inplace=True)
df_latlong=pd.merge(df1,df_confirmed,on=['Country','Province/State'])
df_latlong.head()
fig=px.density_mapbox(df_latlong,lat='Lat',lon='Long',hover_name='Province/State',hover_data=['Confirmed','Deaths','Recovered'],
animation_frame='Date',color_continuous_scale='Portland',radius=7,zoom=0,height=600)
fig.update_layout(title='Worldwide Corona Virus Cases')
fig.update_layout(mapbox_style="open-street-map",mapbox_center_lon=0)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})